package com.wy.business.developer.developer.actions;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wy.business.developer.developer.services.RegistService;
import com.wy.framework.actions.AbstractBaseAction;
import com.wy.framework.dao.ErrorSqlException;
import com.wy.framework.exceptions.ServiceException;

/**
 * 项目名称：openportal
 * 类名称：RegistAction
 * 类描述：注册
 * 创建人：张旭星
 * 创建时间：2016-3-22 下午3:11:09
 * 修改人：张旭星
 * 修改时间：2016-3-22 下午3:11:09
 * 版本信息：@version 1.0
 * Copyright (c) 2016万雍科技（上海）有限公司-版权所有  
 * 修改备注：
 * @version 
 */
@ParentPackage("json")
@Namespace("/developer")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class RegistAction extends AbstractBaseAction {
	private static final long serialVersionUID = 1L;
	private static Log logger = LogFactory.getLog(RegistAction.class);

	@Autowired
	private RegistService registService;
	
	private List<Map> rows;
	private List<Map> orgInfo;
	private String id;
	private String boolFlg;

	/**
	 * Function Name               regist                                   
	 * @return
	 * @throws ServiceException          		             
	 * @description 注册
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-1-4 下午1:46:43           张旭星                     Initial
	 **********************************************************************
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Action(value = "regist", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String regist() throws ServiceException {
		String useremail = ServletActionContext.getRequest().getParameter("useremail");
		String password = ServletActionContext.getRequest().getParameter("password");
		String name = ServletActionContext.getRequest().getParameter("name");
		String sex = ServletActionContext.getRequest().getParameter("sex");
		String enterprise_info = ServletActionContext.getRequest().getParameter("enterprise_info");
		String ID = ServletActionContext.getRequest().getParameter("ID");
		String mobile_phone = ServletActionContext.getRequest().getParameter("mobile_phone");
		try {
			rspCode = registService.saveDeveloper(useremail,password,name,sex,enterprise_info,ID,mobile_phone);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ErrorSqlException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/**
	 * Function Name               existsUserId                                   
	 * @return
	 * @throws ServiceException          		             
	 * @description 账号是否存在
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-3-26 下午4:56:51           张旭星                     Initial
	 **********************************************************************
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Action(value = "judgeUserId", 
	interceptorRefs = { @InterceptorRef("sessionStack") }, 
	results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false","root","boolFlg"}) })
	public String judgeUserId() throws ServiceException {
		String useremail = ServletActionContext.getRequest().getParameter("useremail");
		try {
			boolFlg = registService.getJudgeUserId(useremail);
		} catch (ErrorSqlException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String getBoolFlg() {
		return boolFlg;
	}

	public List<Map> getRows() {
		return rows;
	}

	public List<Map> getOrgInfo() {
		return orgInfo;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getTotal() {
		if (rows == null) {
			return 0;
		} else {
			return rows.size();
		}
	}

}
